|
|
 |
|
|
|
|
' See where the projections of two segments cross.
' Return true if the segments cross, false
' otherwise. Private Function FindCrossing(ByVal ax1 As Single, _
ByVal ay1 As Single, ByVal az1 As Single, _
ByVal ax2 As Single, ByVal ay2 As Single, _
ByVal az2 As Single, ByVal bx1 As Single, _
ByVal by1 As Single, ByVal bz1 As Single, _
ByVal bx2 As Single, ByVal by2 As Single, _
ByVal bz2 As Single, _
ByRef X As Single, ByRef Y As Single, _
ByRef z1 As Single, ByRef z2 As Single) _
As Boolean
Dim dxa As Single
Dim dya As Single
Dim dza As Single
Dim dxb As Single
Dim dyb As Single
Dim dzb As Single
Dim t1 As Single
Dim t2 As Single
Dim denom As Single
dxa = ax2 - ax1
dya = ay2 - ay1
dxb = bx2 - bx1
dyb = by2 - by1
FindCrossing = False
denom = dxb * dya - dyb * dxa ' If the segments are parallel, stop. If denom < 0.01 And denom > -0.01 Then Exit Function
t2 = (ax1 * dya - ay1 * dxa - bx1 * dya + by1 * dxa) / _
denom
If t2 < 0 Or t2 > 1 Then Exit Function
t1 = (ax1 * dyb - ay1 * dxb - bx1 * dyb + by1 * dxb) / _
denom
If t1 < 0 Or t1 > 1 Then Exit Function
' Compute the points of overlap. X = ax1 + t1 * dxa
Y = ay1 + t1 * dya
dza = az2 - az1
dzb = bz2 - bz1
z1 = az1 + t1 * dza
z2 = bz1 + t2 * dzb
FindCrossing = True
End Function |
|
|
|
|
|